/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFPlanoContas.java
 *
 * Created on 29/09/2012, 21:43:13
 */

package ecommercial;

import ecommercial.Classes.ClassConecta;
import ecommercial.Classes.ComboItem;
import ecommercial.Classes.Filiais;
import ecommercial.Classes.GrupoContas;
import ecommercial.Classes.PlanoContas;
import ecommercial.Classes.TipoContas;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

/**
 *
 * @author Luciano Carrafa Benfica
 *
 *
 */
public class jFPlanoContas extends javax.swing.JDialog {

    /** Creates new form jFPlanoContas */
    public jFPlanoContas() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jToolBar1 = new javax.swing.JToolBar();
        buscarjButton = new javax.swing.JButton();
        novojButton = new javax.swing.JButton();
        editarjButton = new javax.swing.JButton();
        salvarjButton = new javax.swing.JButton();
        salvarMaisjButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        alterarjButton = new javax.swing.JButton();
        excluirjButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        sairjButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        getPlanodeContasjTree = new javax.swing.JTree();
        jPanel3 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel4 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        nomeContajTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        filialjComboBox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        atualizaFilialjButton = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        contaPaijComboBox = new javax.swing.JComboBox();
        atualizaContaPaijButton = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        grupoContajComboBox = new javax.swing.JComboBox();
        cadastraGrupoContajButton = new javax.swing.JButton();
        atualizaGrupoContajButton = new javax.swing.JButton();
        grupojComboBox = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        tipoContajComboBox = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        numeroContajTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        cadastraTipoContajButton = new javax.swing.JButton();
        atualizaTipoContajButton = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jPanel8 = new javax.swing.JPanel();
        simjRadioButton = new javax.swing.JRadioButton();
        naojRadioButton = new javax.swing.JRadioButton();
        jPanel9 = new javax.swing.JPanel();
        patrimoniojRadioButton = new javax.swing.JRadioButton();
        orcamentojRadioButton = new javax.swing.JRadioButton();
        resultadojRadioButton = new javax.swing.JRadioButton();
        jPanel10 = new javax.swing.JPanel();
        jPanel11 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        historicojTextArea = new javax.swing.JTextArea();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        atualizaJTreejButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ecommercial.EcommercialApp.class).getContext().getResourceMap(jFPlanoContas.class);
        jToolBar1.setBackground(resourceMap.getColor("jToolBar1.background")); // NOI18N
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        buscarjButton.setBackground(resourceMap.getColor("buscarjButton.background")); // NOI18N
        buscarjButton.setIcon(resourceMap.getIcon("buscarjButton.icon")); // NOI18N
        buscarjButton.setText(resourceMap.getString("buscarjButton.text")); // NOI18N
        buscarjButton.setFocusable(false);
        buscarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buscarjButton.setName("buscarjButton"); // NOI18N
        buscarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buscarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(buscarjButton);

        novojButton.setBackground(resourceMap.getColor("novojButton.background")); // NOI18N
        novojButton.setIcon(resourceMap.getIcon("novojButton.icon")); // NOI18N
        novojButton.setText(resourceMap.getString("novojButton.text")); // NOI18N
        novojButton.setFocusable(false);
        novojButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        novojButton.setName("novojButton"); // NOI18N
        novojButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        novojButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novojButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(novojButton);

        editarjButton.setBackground(resourceMap.getColor("editarjButton.background")); // NOI18N
        editarjButton.setIcon(resourceMap.getIcon("editarjButton.icon")); // NOI18N
        editarjButton.setText(resourceMap.getString("editarjButton.text")); // NOI18N
        editarjButton.setFocusable(false);
        editarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editarjButton.setName("editarjButton"); // NOI18N
        editarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(editarjButton);

        salvarjButton.setBackground(resourceMap.getColor("salvarjButton.background")); // NOI18N
        salvarjButton.setIcon(resourceMap.getIcon("salvarjButton.icon")); // NOI18N
        salvarjButton.setText(resourceMap.getString("salvarjButton.text")); // NOI18N
        salvarjButton.setFocusable(false);
        salvarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        salvarjButton.setName("salvarjButton"); // NOI18N
        salvarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        salvarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(salvarjButton);

        salvarMaisjButton.setBackground(resourceMap.getColor("salvarMaisjButton.background")); // NOI18N
        salvarMaisjButton.setIcon(resourceMap.getIcon("salvarMaisjButton.icon")); // NOI18N
        salvarMaisjButton.setText(resourceMap.getString("salvarMaisjButton.text")); // NOI18N
        salvarMaisjButton.setFocusable(false);
        salvarMaisjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        salvarMaisjButton.setName("salvarMaisjButton"); // NOI18N
        salvarMaisjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(salvarMaisjButton);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jToolBar1.add(jSeparator1);

        alterarjButton.setBackground(resourceMap.getColor("alterarjButton.background")); // NOI18N
        alterarjButton.setIcon(resourceMap.getIcon("alterarjButton.icon")); // NOI18N
        alterarjButton.setText(resourceMap.getString("alterarjButton.text")); // NOI18N
        alterarjButton.setFocusable(false);
        alterarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        alterarjButton.setName("alterarjButton"); // NOI18N
        alterarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(alterarjButton);

        excluirjButton.setBackground(resourceMap.getColor("excluirjButton.background")); // NOI18N
        excluirjButton.setIcon(resourceMap.getIcon("excluirjButton.icon")); // NOI18N
        excluirjButton.setText(resourceMap.getString("excluirjButton.text")); // NOI18N
        excluirjButton.setFocusable(false);
        excluirjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        excluirjButton.setName("excluirjButton"); // NOI18N
        excluirjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(excluirjButton);

        jSeparator2.setName("jSeparator2"); // NOI18N
        jToolBar1.add(jSeparator2);

        sairjButton.setBackground(resourceMap.getColor("sairjButton.background")); // NOI18N
        sairjButton.setIcon(resourceMap.getIcon("sairjButton.icon")); // NOI18N
        sairjButton.setText(resourceMap.getString("sairjButton.text")); // NOI18N
        sairjButton.setFocusable(false);
        sairjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sairjButton.setName("sairjButton"); // NOI18N
        sairjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sairjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(sairjButton);

        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jPanel2.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        getPlanodeContasjTree.setName("getPlanodeContasjTree"); // NOI18N
        jScrollPane1.setViewportView(getPlanodeContasjTree);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel3.setName("jPanel3"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel4.setBackground(resourceMap.getColor("jPanel4.background")); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N

        jPanel6.setBackground(resourceMap.getColor("jPanel6.background")); // NOI18N
        jPanel6.setName("jPanel6"); // NOI18N

        nomeContajTextField.setText(resourceMap.getString("nomeContajTextField.text")); // NOI18N
        nomeContajTextField.setName("nomeContajTextField"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel2.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        filialjComboBox.setName("filialjComboBox"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        atualizaFilialjButton.setIcon(resourceMap.getIcon("atualizaFilialjButton.icon")); // NOI18N
        atualizaFilialjButton.setText(resourceMap.getString("atualizaFilialjButton.text")); // NOI18N
        atualizaFilialjButton.setContentAreaFilled(false);
        atualizaFilialjButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        atualizaFilialjButton.setName("atualizaFilialjButton"); // NOI18N
        atualizaFilialjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaFilialjButtonActionPerformed(evt);
            }
        });

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        contaPaijComboBox.setName("contaPaijComboBox"); // NOI18N

        atualizaContaPaijButton.setIcon(resourceMap.getIcon("atualizaContaPaijButton.icon")); // NOI18N
        atualizaContaPaijButton.setText(resourceMap.getString("atualizaContaPaijButton.text")); // NOI18N
        atualizaContaPaijButton.setContentAreaFilled(false);
        atualizaContaPaijButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        atualizaContaPaijButton.setName("atualizaContaPaijButton"); // NOI18N
        atualizaContaPaijButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaContaPaijButtonActionPerformed(evt);
            }
        });

        jLabel6.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel6.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        grupoContajComboBox.setName("grupoContajComboBox"); // NOI18N

        cadastraGrupoContajButton.setIcon(resourceMap.getIcon("cadastraGrupoContajButton.icon")); // NOI18N
        cadastraGrupoContajButton.setText(resourceMap.getString("cadastraGrupoContajButton.text")); // NOI18N
        cadastraGrupoContajButton.setContentAreaFilled(false);
        cadastraGrupoContajButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cadastraGrupoContajButton.setName("cadastraGrupoContajButton"); // NOI18N

        atualizaGrupoContajButton.setIcon(resourceMap.getIcon("atualizaGrupoContajButton.icon")); // NOI18N
        atualizaGrupoContajButton.setText(resourceMap.getString("atualizaGrupoContajButton.text")); // NOI18N
        atualizaGrupoContajButton.setContentAreaFilled(false);
        atualizaGrupoContajButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        atualizaGrupoContajButton.setName("atualizaGrupoContajButton"); // NOI18N
        atualizaGrupoContajButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaGrupoContajButtonActionPerformed(evt);
            }
        });

        grupojComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "DISPONÍVEL", "REALISÁVEL", "EXIGÍVEL" }));
        grupojComboBox.setName("grupojComboBox"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel3.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        tipoContajComboBox.setName("tipoContajComboBox"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel5.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        numeroContajTextField.setText(resourceMap.getString("numeroContajTextField.text")); // NOI18N
        numeroContajTextField.setName("numeroContajTextField"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel7.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        cadastraTipoContajButton.setIcon(resourceMap.getIcon("cadastraTipoContajButton.icon")); // NOI18N
        cadastraTipoContajButton.setText(resourceMap.getString("cadastraTipoContajButton.text")); // NOI18N
        cadastraTipoContajButton.setContentAreaFilled(false);
        cadastraTipoContajButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        cadastraTipoContajButton.setName("cadastraTipoContajButton"); // NOI18N
        cadastraTipoContajButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastraTipoContajButtonActionPerformed(evt);
            }
        });

        atualizaTipoContajButton.setIcon(resourceMap.getIcon("atualizaTipoContajButton.icon")); // NOI18N
        atualizaTipoContajButton.setText(resourceMap.getString("atualizaTipoContajButton.text")); // NOI18N
        atualizaTipoContajButton.setContentAreaFilled(false);
        atualizaTipoContajButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        atualizaTipoContajButton.setName("atualizaTipoContajButton"); // NOI18N
        atualizaTipoContajButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaTipoContajButtonActionPerformed(evt);
            }
        });

        jPanel7.setBackground(resourceMap.getColor("jPanel7.background")); // NOI18N
        jPanel7.setName("jPanel7"); // NOI18N

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel8.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel8.border.titleColor"))); // NOI18N
        jPanel8.setName("jPanel8"); // NOI18N

        buttonGroup2.add(simjRadioButton);
        simjRadioButton.setSelected(true);
        simjRadioButton.setText(resourceMap.getString("simjRadioButton.text")); // NOI18N
        simjRadioButton.setActionCommand(resourceMap.getString("simjRadioButton.actionCommand")); // NOI18N
        simjRadioButton.setName("simjRadioButton"); // NOI18N

        buttonGroup2.add(naojRadioButton);
        naojRadioButton.setText(resourceMap.getString("naojRadioButton.text")); // NOI18N
        naojRadioButton.setActionCommand(resourceMap.getString("naojRadioButton.actionCommand")); // NOI18N
        naojRadioButton.setName("naojRadioButton"); // NOI18N

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(simjRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 72, Short.MAX_VALUE)
                .addComponent(naojRadioButton)
                .addGap(26, 26, 26))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(simjRadioButton)
                    .addComponent(naojRadioButton))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel9.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel9.border.titleColor"))); // NOI18N
        jPanel9.setName("jPanel9"); // NOI18N

        buttonGroup1.add(patrimoniojRadioButton);
        patrimoniojRadioButton.setSelected(true);
        patrimoniojRadioButton.setText(resourceMap.getString("patrimoniojRadioButton.text")); // NOI18N
        patrimoniojRadioButton.setActionCommand(resourceMap.getString("patrimoniojRadioButton.actionCommand")); // NOI18N
        patrimoniojRadioButton.setName("patrimoniojRadioButton"); // NOI18N

        buttonGroup1.add(orcamentojRadioButton);
        orcamentojRadioButton.setText(resourceMap.getString("orcamentojRadioButton.text")); // NOI18N
        orcamentojRadioButton.setActionCommand(resourceMap.getString("orcamentojRadioButton.actionCommand")); // NOI18N
        orcamentojRadioButton.setName("orcamentojRadioButton"); // NOI18N

        buttonGroup1.add(resultadojRadioButton);
        resultadojRadioButton.setText(resourceMap.getString("resultadojRadioButton.text")); // NOI18N
        resultadojRadioButton.setActionCommand(resourceMap.getString("resultadojRadioButton.actionCommand")); // NOI18N
        resultadojRadioButton.setName("resultadojRadioButton"); // NOI18N

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(patrimoniojRadioButton)
                        .addGap(18, 18, 18)
                        .addComponent(orcamentojRadioButton))
                    .addComponent(resultadojRadioButton))
                .addContainerGap(37, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(patrimoniojRadioButton)
                    .addComponent(orcamentojRadioButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(resultadojRadioButton))
        );

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(36, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel10.setBackground(resourceMap.getColor("jPanel10.background")); // NOI18N
        jPanel10.setName("jPanel10"); // NOI18N

        jPanel11.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel11.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("jPanel11.border.titleColor"))); // NOI18N
        jPanel11.setName("jPanel11"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        historicojTextArea.setColumns(20);
        historicojTextArea.setRows(5);
        historicojTextArea.setName("historicojTextArea"); // NOI18N
        jScrollPane3.setViewportView(historicojTextArea);

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addComponent(jPanel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(jPanel6Layout.createSequentialGroup()
                                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel6Layout.createSequentialGroup()
                                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(jPanel6Layout.createSequentialGroup()
                                                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addComponent(nomeContajTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                                                            .addComponent(jLabel2)
                                                            .addComponent(contaPaijComboBox, 0, 186, Short.MAX_VALUE)
                                                            .addComponent(grupoContajComboBox, 0, 186, Short.MAX_VALUE))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                            .addComponent(cadastraGrupoContajButton, 0, 0, Short.MAX_VALUE)
                                                            .addComponent(atualizaContaPaijButton, javax.swing.GroupLayout.PREFERRED_SIZE, 16, Short.MAX_VALUE))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(atualizaGrupoContajButton, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addComponent(jLabel6))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                    .addComponent(jLabel7)
                                                    .addComponent(jLabel3)
                                                    .addComponent(jLabel5)
                                                    .addComponent(tipoContajComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addComponent(grupojComboBox, 0, 200, Short.MAX_VALUE)
                                                    .addComponent(numeroContajTextField)))
                                            .addComponent(filialjComboBox, 0, 435, Short.MAX_VALUE)
                                            .addGroup(jPanel6Layout.createSequentialGroup()
                                                .addComponent(jLabel4)
                                                .addGap(389, 389, 389)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(cadastraTipoContajButton, javax.swing.GroupLayout.PREFERRED_SIZE, 14, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(atualizaTipoContajButton, 0, 0, Short.MAX_VALUE)
                                            .addComponent(atualizaFilialjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 16, Short.MAX_VALUE))))
                                .addGap(91, 91, 91))))
                    .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(filialjComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nomeContajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(numeroContajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(contaPaijComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel6))
                            .addComponent(atualizaContaPaijButton)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(tipoContajComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(atualizaTipoContajButton)
                                        .addComponent(cadastraTipoContajButton)))
                                .addGap(7, 7, 7)
                                .addComponent(jLabel3)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(atualizaGrupoContajButton)
                                .addComponent(cadastraGrupoContajButton)
                                .addGroup(jPanel6Layout.createSequentialGroup()
                                    .addGap(5, 5, 5)
                                    .addComponent(grupojComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(grupoContajComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(atualizaFilialjButton))
                .addGap(18, 18, 18)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel4.TabConstraints.tabTitle"), jPanel4); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane2.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel5.TabConstraints.tabTitle"), jPanel5); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 522, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE)
                .addContainerGap())
        );

        atualizaJTreejButton.setFont(resourceMap.getFont("atualizaJTreejButton.font")); // NOI18N
        atualizaJTreejButton.setText(resourceMap.getString("atualizaJTreejButton.text")); // NOI18N
        atualizaJTreejButton.setContentAreaFilled(false);
        atualizaJTreejButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        atualizaJTreejButton.setName("atualizaJTreejButton"); // NOI18N
        atualizaJTreejButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaJTreejButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(atualizaJTreejButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(atualizaJTreejButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 839, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    ClassConecta conexao = new ClassConecta();

    ComboItem comboFilial;
    ComboItem comboContaPai;
    ComboItem comboTipoConta;
    ComboItem comboGrupoConta;

    public int codConta = 1;



    public void expandAll(JTree tree) {
        TreeNode root = (TreeNode) tree.getModel().getRoot();
        expandAll(tree, new TreePath(root));
    }

    private void expandAll(JTree tree, TreePath parent) {
        TreeNode node = (TreeNode) parent.getLastPathComponent();
        if (node.getChildCount() >= 0) {
            for (Enumeration e = node.children(); e.hasMoreElements();) {
                TreeNode n = (TreeNode) e.nextElement();
                TreePath path = parent.pathByAddingChild(n);
                expandAll(tree, path);
            }
        }
        tree.expandPath(parent);
    // tree.collapsePath(parent);
    }



//    public void getPlanodeContasjTree(){
//       //Consultar situacoes agrupadas
//        PlanoContas oPlanoContas = new PlanoContas();
//
////        if (codPessoa > 0){
////            oSituacao.setCodCliente(codPessoa);
////        }else{
////            oSituacao.setCodCliente(0);
////        }
//
//        ResultSet resultSet = null;
//
//        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Plano de Contas");
//        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Todas");
////        treeNode1.add(treeNode2);//Para tirar o todas, comente esta linha e e deixa assim a linha de cima no final javax.swing.tree.DefaultMutableTreeNode()
//
//        try {
//            resultSet = oPlanoContas.getConsultar();
//            resultSet.first();
//        } catch (SQLException ex) {
//            Logger.getLogger(jFPlanoContas.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        try {
//            while (resultSet.next()) {
//
//                  treeNode2 = new javax.swing.tree.DefaultMutableTreeNode(resultSet.getString("NUM_CONTA")+"("+resultSet.getString("Nome_Conta")+")");
//                  treeNode1.add(treeNode2);
//
//            }
//            getPlanodeContasjTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
//
//        } catch (SQLException ex) {
//            Logger.getLogger(jFPlanoContas.class.getName()).log(Level.SEVERE, null, ex);
//        }
//
//    }



    private void sairjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairjButtonActionPerformed
        // TODO add your handling code here:
        if (!novojButton.isEnabled()){
                Object[] options = {"Sim", "Não"};
                int sd = JOptionPane.showOptionDialog(null, "Deseja realmente SAIR?", "Confirmação do Sistema!", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
                if (sd != 0) {
                    return;
                }

                this.dispose();

            }else{

                this.dispose();

            }
    }//GEN-LAST:event_sairjButtonActionPerformed

    private void atualizaFilialjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaFilialjButtonActionPerformed
        // TODO add your handling code here:
        try {
            Filiais oFilial = new Filiais();
            ResultSet rs = null;

            rs = oFilial.getConsultar();
            filialjComboBox.removeAllItems();
            filialjComboBox.addItem("");
            while (rs.next()) {
                filialjComboBox.addItem(new ComboItem(rs.getInt("COD_PESSOA"), rs.getString("PESSOA")));
            }
            filialjComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(Filiais.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_atualizaFilialjButtonActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        ClassConecta.conecta();

        salvarjButton.setEnabled(false);
        salvarMaisjButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        novojButton.setEnabled(true);

        filialjComboBox.grabFocus();

        buscarjButtonActionPerformed(null);

    }//GEN-LAST:event_formWindowOpened

    private void buscarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarjButtonActionPerformed
        // TODO add your handling code here:

        atualizaFilialjButtonActionPerformed(null);
        atualizaTipoContajButtonActionPerformed(null);
        atualizaGrupoContajButtonActionPerformed(null);
        atualizaContaPaijButtonActionPerformed(null);

//        getPlanodeContasjTree();

    }//GEN-LAST:event_buscarjButtonActionPerformed

    private void atualizaTipoContajButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaTipoContajButtonActionPerformed
        // TODO add your handling code here:
        try {
            TipoContas oTipoConta = new TipoContas();
            ResultSet rs = null;

            rs = oTipoConta.getConsultar();
            tipoContajComboBox.removeAllItems();
            tipoContajComboBox.addItem("");
            while (rs.next()) {
                tipoContajComboBox.addItem(new ComboItem(rs.getInt("COD_TIPO_CONTA"), rs.getString("TIPO_CONTA")));
            }
            tipoContajComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(TipoContas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_atualizaTipoContajButtonActionPerformed

    private void cadastraTipoContajButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastraTipoContajButtonActionPerformed
        // TODO add your handling code here:
        jFTipoContas oFormTipoContas = new jFTipoContas();

        oFormTipoContas.setTitle("Tipo Contas");
        oFormTipoContas.setDefaultCloseOperation(jFTipoContas.DO_NOTHING_ON_CLOSE);
        oFormTipoContas.pack();
        oFormTipoContas.setModal(true);
        oFormTipoContas.setLocationRelativeTo(null);
        oFormTipoContas.setVisible(true);
    }//GEN-LAST:event_cadastraTipoContajButtonActionPerformed

    private void atualizaGrupoContajButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaGrupoContajButtonActionPerformed
        // TODO add your handling code here:
        try {
            GrupoContas oGrupoConta = new GrupoContas();
            ResultSet rs = null;

            rs = oGrupoConta.getConsultar();
            grupoContajComboBox.removeAllItems();
            while (rs.next()) {
                grupoContajComboBox.addItem(new ComboItem(rs.getInt("COD_GRUPO_CONTA"), rs.getString("GRUPO")));
            }
            grupoContajComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(TipoContas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_atualizaGrupoContajButtonActionPerformed

    private void novojButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novojButtonActionPerformed
        // TODO add your handling code here:
        novojButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        buscarjButton.setEnabled(true);
        salvarjButton.setEnabled(true);
        salvarMaisjButton.setEnabled(true);
        filialjComboBox.grabFocus();
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFBairros.class.getName()).log(Level.SEVERE, null, ex);
        }
        atualizaFilialjButtonActionPerformed(null);
        atualizaTipoContajButtonActionPerformed(null);
        atualizaGrupoContajButtonActionPerformed(null);
        nomeContajTextField.setText("");
        numeroContajTextField.setText("");
        grupoContajComboBox.setSelectedItem(" ");
        
    }//GEN-LAST:event_novojButtonActionPerformed

    private void salvarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarjButtonActionPerformed
        // TODO add your handling code here:
            salvarjButton.setEnabled(false);
            salvarMaisjButton.setEnabled(false);
            alterarjButton.setEnabled(false);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);
            editarjButton.setEnabled(true);

        PlanoContas oPlanoConta = new PlanoContas();
        
            comboFilial = (ComboItem) filialjComboBox.getSelectedItem();        //PEGA O ID DO COMBOBOX
            comboContaPai = (ComboItem) contaPaijComboBox.getSelectedItem();    //PEGA O ID DO COMBOBOX
            comboTipoConta = (ComboItem) tipoContajComboBox.getSelectedItem();  //PEGA O ID DO COMBOBOX
            comboGrupoConta = (ComboItem) grupoContajComboBox.getSelectedItem();//PEGA O ID DO COMBOBOX



        if (filialjComboBox.getSelectedItem().equals("")){

            JOptionPane.showMessageDialog(null, "O campo FILIAL é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            return;

        }else if (nomeContajTextField.getText().equals("")){

            JOptionPane.showMessageDialog(null, "O campo NOME CONTA é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            return;

        }else if (numeroContajTextField.getText().equals("")){

            JOptionPane.showMessageDialog(null, "O campo NÚMERO DA CONTA é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            return;

        }else if (tipoContajComboBox.getSelectedItem().equals("")){

            JOptionPane.showMessageDialog(null, "O campo TIPO CONTA é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            return;

        }else if (grupoContajComboBox.getSelectedItem().equals("")){

            JOptionPane.showMessageDialog(null, "O campo GRUPO CONTA é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            return;

        }else if (grupoContajComboBox.getSelectedItem().equals("")){

            JOptionPane.showMessageDialog(null, "O campo GRUPO é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            return;

        }else{
            
            oPlanoConta.setCod_filial(comboFilial.getId());
            oPlanoConta.setNome_conta(nomeContajTextField.getText().trim().toUpperCase());
            oPlanoConta.setNum_conta(numeroContajTextField.getText());

            if (comboContaPai.getId() == -1){               // VERIFICA SE O CAMPO IGUAL A -1
            oPlanoConta.setCod_conta_pai(null);             // SETA UM VALOR NULO
            }else{
            oPlanoConta.setCod_conta_pai(comboContaPai.getId());
            }
            System.out.println(comboContaPai.getId());
            oPlanoConta.setCod_tipo_conta(comboTipoConta.getId());
            oPlanoConta.setCod_grupo_conta(comboGrupoConta.getId());
            oPlanoConta.setGrupo(grupoContajComboBox.getSelectedItem().toString());
            oPlanoConta.setCirculante(buttonGroup2.getSelection().getActionCommand());
            oPlanoConta.setClassificacao(buttonGroup1.getSelection().getActionCommand());
            oPlanoConta.setHistorico_padrao(historicojTextArea.getText());
            oPlanoConta.setCadastrar();

            try {
                ClassConecta.con.commit();
                ClassConecta.con.setAutoCommit(true);
            } catch (SQLException ex) {
                Logger.getLogger(jFPlanoContas.class.getName()).log(Level.SEVERE, null, ex);
            }

            
        }

    }//GEN-LAST:event_salvarjButtonActionPerformed

    private void atualizaContaPaijButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaContaPaijButtonActionPerformed
        // TODO add your handling code here:
        try {
            PlanoContas oPlanoConta = new PlanoContas();
            ResultSet rs = null;

            rs = oPlanoConta.getConsultar();
            contaPaijComboBox.removeAllItems();
            contaPaijComboBox.addItem(new ComboItem(-1, ""));
            while (rs.next()) {
                contaPaijComboBox.addItem(new ComboItem(rs.getInt("COD_CONTA"), rs.getString("NOME_CONTA")));
            }
            contaPaijComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(TipoContas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_atualizaContaPaijButtonActionPerformed

    private void atualizaJTreejButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaJTreejButtonActionPerformed
        // TODO add your handling code here:
        DefaultTreeModel modelTree = null;
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("PLANO DE CONTAS");

        //Consultar ata
        PlanoContas oPlanoConta = new PlanoContas();
        oPlanoConta.setCod_conta(codConta);
        oPlanoConta.setNum_conta("NUM_CONTA");
        
        ResultSet rs = null;
        try {
            rs = oPlanoConta.getConsultar();
        } catch (SQLException ex) {
            Logger.getLogger(jFPlanoContas.class.getName()).log(Level.SEVERE, null, ex);
        }
        //Fim consultar ATA

        try {

            while (rs.next()) {
                DefaultMutableTreeNode ata = new DefaultMutableTreeNode(rs.getString(2));
                root.add(ata);

                //Buscar Pauta
                PlanoContas oPlanoContaPai = new PlanoContas();
                oPlanoContaPai.setCod_conta_pai(codConta);
                oPlanoConta.setNome_conta("NOME_CONTA");
                ResultSet rsPauta = null;

                try {
                    rsPauta = oPlanoContaPai.getConsultar();
                } catch (SQLException ex) {
                    Logger.getLogger(jFPlanoContas.class.getName()).log(Level.SEVERE, null, ex);
                }

                //Adicionar
                while (rsPauta.next()) {
                    if (rsPauta.getInt(6) > 0) {

                        if (rs.getInt(1) == rsPauta.getInt(6)) {
                            DefaultMutableTreeNode pauta = new DefaultMutableTreeNode(rsPauta.getString(2));
                            ata.add(pauta);
                        }

                    }


                }

            //Fim buscar Pauta


            }
        } catch (SQLException ex) {
            Logger.getLogger(jFPlanoContas.class.getName()).log(Level.SEVERE, null, ex);
        }


        modelTree = new DefaultTreeModel(root);
        getPlanodeContasjTree.setModel(modelTree);
        expandAll(getPlanodeContasjTree);

    }//GEN-LAST:event_atualizaJTreejButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFPlanoContas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton alterarjButton;
    private javax.swing.JButton atualizaContaPaijButton;
    private javax.swing.JButton atualizaFilialjButton;
    private javax.swing.JButton atualizaGrupoContajButton;
    private javax.swing.JButton atualizaJTreejButton;
    private javax.swing.JButton atualizaTipoContajButton;
    private javax.swing.JButton buscarjButton;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton cadastraGrupoContajButton;
    private javax.swing.JButton cadastraTipoContajButton;
    private javax.swing.JComboBox contaPaijComboBox;
    private javax.swing.JButton editarjButton;
    private javax.swing.JButton excluirjButton;
    private javax.swing.JComboBox filialjComboBox;
    private javax.swing.JTree getPlanodeContasjTree;
    private javax.swing.JComboBox grupoContajComboBox;
    private javax.swing.JComboBox grupojComboBox;
    private javax.swing.JTextArea historicojTextArea;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JRadioButton naojRadioButton;
    private javax.swing.JTextField nomeContajTextField;
    private javax.swing.JButton novojButton;
    private javax.swing.JTextField numeroContajTextField;
    private javax.swing.JRadioButton orcamentojRadioButton;
    private javax.swing.JRadioButton patrimoniojRadioButton;
    private javax.swing.JRadioButton resultadojRadioButton;
    private javax.swing.JButton sairjButton;
    private javax.swing.JButton salvarMaisjButton;
    private javax.swing.JButton salvarjButton;
    private javax.swing.JRadioButton simjRadioButton;
    private javax.swing.JComboBox tipoContajComboBox;
    // End of variables declaration//GEN-END:variables

}
